home *** CD-ROM | disk | FTP | other *** search
/ Windows Undocumented File Formats / Windows Undocumented File Formats.img / CHAP7 / RESTYPES.H < prev   
C/C++ Source or Header  |  1997-07-15  |  4KB  |  149 lines

  1. /**********************************************************************
  2.  *
  3.  * PROGRAM: RES2RC.C
  4.  *
  5.  * PURPOSE: Converts a .RES file to an .RC file
  6.  *
  7.  * Copyright 1997, Mike Wallace and Pete Davis
  8.  *
  9.  * Chapter 7, Resource (.RES) File Format, from Undocumented Windows
  10.  * File Formats, published by R&D Books, an imprint of Miller Freeman, Inc.
  11.  *
  12.  **********************************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. #include "windows.h"
  19. #include "ver.h"
  20.  
  21. /* Declare some global variables */
  22.  
  23. /* This is a list of known resource types, all handled by the program */
  24. char *res_array[] = { "", "CURSOR", "BITMAP", "ICON", "MENU", "DIALOG",
  25.  "STRINGTABLE", "FONTDIR", "FONT", "ACCELERATORS", "RCDATA", "", 
  26.  "GROUP CURSOR", "", "GROUP ICON" };
  27.  
  28. int  INDENT=0;        /* records the current number of indented spaces */
  29. WORD StringCount;
  30. WORD VersionUsed = 0; /* records whether ver.h has been included */
  31.  
  32. /* Define a variable to hold the memory-flags field for the current  */
  33. /* resource.  This is used because for 2 fields (cursor and icon),   */
  34. /* each resource of either type is separated into 2 resources in the */
  35. /* .res file by the rc compiler: data and header.  The correct memory*/
  36. /* flags are set in the first occurrence, but I don't write out the  */
  37. /* resource until I hit the header.  Since we want to write out the  */
  38. /* correct memory flags (e.g., LOADONCALL), we save the flag value in*/
  39. /* this variable, and then use it when we hit the header, instead of */
  40. /* using the header's flag.  It is only saved in the get_mem_flags() */
  41. /* function, since that is the only time we skip a resource header,  */
  42. /* such as for cursors and icons.                                    */
  43. WORD prev_mem_flag=0;
  44.  
  45. /* define the newline and carriage return characters */
  46. #define NL 10
  47. #define CR 13
  48.  
  49. /* define constants for different Version Info block types */
  50. #define STRINGBLOCK 1
  51. #define VARBLOCK    2
  52. #define OTHERBLOCK  3
  53.  
  54. /* define the number of spaces to indent */
  55. #define INDENT_SPACES 3
  56.  
  57. /* define integer values for some resource types - try to make more elegant */
  58. #define CURSOR_TYPE 1
  59. #define ICON_TYPE   3
  60. #define STRING_TYPE 6
  61.  
  62. struct MenuHeader {
  63.    WORD wVersion;
  64.    WORD wReserved;
  65. };
  66.  
  67. struct AccelTableEntry {
  68.    BYTE fFlags;
  69.    WORD wEvent;
  70.    WORD wId;
  71. };
  72.  
  73. /* structure of icon data in .res file */
  74. typedef struct IconDirectoryEntry {
  75.    BYTE  bWidth;
  76.    BYTE  bHeight;
  77.    BYTE  bColorCount;
  78.    BYTE  bReserved;
  79.    WORD  wPlanes;
  80.    WORD  wBitCount;
  81.    DWORD dwBytesInRes;
  82.    WORD  wImageOffset;
  83. } ICONDIRENTRY;
  84.  
  85. /* structure of icon data in .ico file */
  86. typedef struct IconResourceEntry {
  87.    BYTE  bWidth;
  88.    BYTE  bHeight;
  89.    BYTE  bColorCount;
  90.    BYTE  bReserved;
  91.    WORD  wPlanes;
  92.    WORD  wBitCount;
  93.    DWORD dwBytesInRes;
  94.    DWORD dwImageOffset;
  95. } ICONRESENTRY;
  96.  
  97. typedef struct ICONDIR {
  98.    WORD          idReserved;
  99.    WORD          idType;
  100.    WORD          idCount;
  101. } ICONHEADER;
  102.  
  103. /* structure of cursor data in .res file */
  104. typedef struct CursorDirectoryEntry {
  105.    WORD  wWidth;
  106.    WORD  wHeight;
  107.    WORD  wPlanes;
  108.    WORD  wBitCount;
  109.    DWORD dwBytesInRes;
  110.    WORD  wImageOffset;
  111. } CURSORDIRENTRY;
  112.  
  113. /* structure of cursor data in .cur file */
  114. typedef struct CursorResourceEntry {
  115.    BYTE  bWidth;
  116.    BYTE  bHeight;
  117.    BYTE  bColorCount;
  118.    BYTE  bReserved;
  119.    WORD  wXHotSpot;
  120.    WORD  wYHotSpot;
  121.    DWORD dwBytesInRes;
  122.    DWORD dwImageOffset;
  123. } CURSORRESENTRY;
  124.  
  125. typedef struct CURSORDIR {
  126.    WORD cdReserved;
  127.    WORD cdType;
  128.    WORD cdCount;
  129. } CURSORHEADER;
  130.  
  131. typedef struct DIALOGINFO {
  132.    DWORD lStyle;
  133.    BYTE  bNumberOfItems;
  134.    WORD  x;
  135.    WORD  y;
  136.    WORD  width;
  137.    WORD  height;
  138. } DIALOGHEADER;
  139.  
  140. typedef struct DIALOGCONTROL {
  141.    WORD  x;
  142.    WORD  y;
  143.    WORD  width;
  144.    WORD  height;
  145.    WORD  id;
  146.    DWORD lStyle;
  147. } CONTROLDATA;
  148.  
  149.